/// @tags: Prefix
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5;

int p[N], maxx[N], stk[N];

inline int main() {
  int t;
  cin >> t;
  for (int i = 1, n; i <= t; ++i) {
    cin >> n;
    memset(maxx, 0, sizeof(maxx));
    for (int j = 1; j <= n; ++j) {
      cin >> p[j];
      maxx[j] = max(maxx[j - 1], p[j]);
    }
    int k = n;
    while (k > 0) {
      int tmp = k, top = 0;
      do { stk[++top] = p[k]; } while (p[k--] != maxx[tmp]);
      while (top) cout << stk[top--] << ' ';
    }
    cout << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B Card Deck.in", "r", stdin);
  freopen("B Card Deck.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
